<html>
	<body>
	<img src="images/management-agents.png" width="800"/>
	
	<p>Hasthi has many types of agents, following shows how to integrate the in-memory agent with our services. When integration is complete, 
	please fill this <a href="http://spreadsheets.google.com/viewform?key=pJJCUDThFdemRpDq__zrHFg">form</a> to provide details about the installation</p>
		
<h1><a name="xsul1">Integrate with XSUL services</a></h1>
	<ol>
			<li>Download <a href="http://extreme.indiana.edu/hasthi/lead/xsul-hasthi-agent.zip">XSUL based distribution</a></li>
			<li>Unzip and add included jars to your classpath. Most jar versions are flexible, so if you have different version of the same jar,
			e.g. log4j jar most probabaly that is ok. Hasthi types jar is complied with xmlbeans-2.3, but if needed I can give you a 2.2 compiled one.</li>
			<li>Integrate with your code base
		<h4>Integrate with XSUL2</h4>
		If you use XSUL2, you will have a code like following. To find the code, search for references for XmlBeansBasedService class 
<pre>
XmlBeansBasedService xbeanBasedService = new XmlBeansBasedService("xregistry", cwsdlLoc,
                        new XregistryXmlBeansWrapper(globalContext));
cmsvc = httpServices.addService(xbeanBasedService)
</pre>                
             
Replace the code with the following, you have to lad the    mngBootstrapNode from your configuration, and for this installation it should
point to tyr12.cs.indiana.edu.           
                
<pre>                		
String mngBootstrapNode = .... //loaded from configuration
ExtendedXbeanBasedService extendedXbeanBasedService = new ExtendedXbeanBasedService("xregistry", cwsdlLoc,
                new XregistryXmlBeansWrapper(globalContext));
cmsvc = httpServices.addService(extendedXbeanBasedService);
extendedXbeanBasedService.initManagmentAgent(mngBootstrapNode,httpBasedServices);
</pre>
					
		<h4>Integrate With XSUL1</h4>
		If say you use XSUL1 style if you have a class that extends from xsul.processor.soap_over_http.SoapHttpDynamicInfosetProcessor. In there
		you have to wrap your message-processing-code with the following.
		
		
<ol>
<li>Define a class parameter 	private XsulBasedWSDMProcessor processor</li>
<li>
Override the start() method of the SoapHttpDynamicInfosetProcessor, to look like following
<pre>
public void start(){
	super.start();
	String mngBootstrapNode = .... //loaded from configuration
	QName serviceName = .. //your service name
	Properties properties = new Properties();
	properties.put(HasthiOptions.BOOTSTRAP_NODE,mngBootstrapNode);
	Xsul1SystemHandle systemHandle = new Xsul1SystemHandle(serviceName, serviceName, this);
	ManagementAgentContext context = new ManagementAgentContext(baseContext);
	processor = new XsulBasedWSDMProcessor(context);
	processor.addResource(systemHandle);
}
</pre>		
</li>
		
<li> If you are not using processHttpXml(..) method in your calss SoapHttpDynamicInfosetProcessor, add following method. Otherwise 
talk to me </li>
<pre>   
public XmlDocument processHttpXml(HttpServerRequest req, HttpServerResponse res,
        XmlDocument document) throws DynamicInfosetProcessorException {
    try {
        XSULMessageContext hasthiMessageContext = new XSULMessageContext(document, "");
        if (processor.isKnownMessage(hasthiMessageContext)) {
            SoapUtil soapUtil = SoapUtil.selectSoapFragrance(document, new SoapUtil[] {
                    Soap12Util.getInstance(), Soap11Util.getInstance() });
            XmlObject responseAsXmlbeans = processor.processeMessage(hasthiMessageContext);
            return soapUtil.wrapBodyContent(XBeansUtil
                    .xmlObjectToXmlElement(responseAsXmlbeans));
        } else {
            try {
                long start = System.currentTimeMillis();
                ((ManagedServiceHandle) (systemHandle)).requestRecived();
                XmlDocument resposne = super.processHttpXml(req, res, document);
                ((ManagedServiceHandle) (systemHandle)).requestSucessful(System
                        .currentTimeMillis()
                        - start);
                return resposne;
            } catch (Exception e) {
                ((ManagedServiceHandle) (systemHandle)).requestFalied();
                throw new MessageProcessingException(e.getMessage(), e);
            }
        }
    } catch (HasthiException e) {
        throw new DynamicInfosetInvokerException(e.getMessage(), e);
    }
}
</pre>
</li>
</ol>		
		
<h1>Integrate with Axis2</h1>
		
		
		<ol>
			<li>Download <a href="http://extreme.indiana.edu/hasthi/lead/axis2-hasthi-agent.zip">Axis2 based distribution</a></li>
			<li>Shutdown your tomcat</li>
			<li>unzip and copy jarfiles in the distribution lib directory to the $TOMCAT_HOME/webapps/axis2/WEB-INF/lib 
			and copy the hasthi-agent.mar file to the $TOMCAT_HOME/webapps/axis2/WEB-INF/modules</li>
		    <li>Edit the $TOMCAT_HOME/webapps/axis2/WEB-INF/conf/axis2.xml to do following</li>
		    	<ul>
		    		<li>Add following to the Global Modules, search for "Global Modules" and add the a entry like following with the addressing entry
		    		 (&lt;module ref="addressing"/&gt;). 
    					<pre>&lt;module ref="hasthi-agent"/&gt;</pre>
		    		</li>
		    		<li>
		    		Add following among other parameters in the top of the file. You have to replace the http://linbox3.extreme.indiana.edu:7777/ with the 
		    		address of your tomcat.
		    		<pre> 
&lt;parameter name="hasthi.boostrapHost" locked="false"&gt;tyr12.cs.indiana.edu&lt;/parameter&gt;
&lt;parameter name="hasthi.axis2tomcatendpoint" locked="false"&gt;http://linbox3.extreme.indiana.edu:7777/&lt;/parameter&gt;
    					</pre>
		    		</li>
		    	</ul>
		    	<li>Restart tomcat, and go to <a href="http://tyr12.cs.indiana.edu:9002">http://tyr12.cs.indiana.edu:9002</a> and you should 
		    	see your service in the listing of this web page. This agent only handle axis2 with a one service. If more than one is there, it will show the name
		    	of the first service it found. So remove the default version service in axis2 and only leave our services in Axis2.  
		    	</li>
		    	<li>If anything goes worng, ask for my help</li>
		</ol>
		<h1>LookingUp Dependencies and Notify Errors</h1>
		<p>Hasthi also acts as a service registry, and using Hasthi, a service can find a service instance given the service type with 
		the “ResolveServiceDependancy” operation. For an example, portal can use Hasthi to find the current registry location using 
		this operation. For most services, the locations of other services are provided via LEAD context header; therefore, this feature 
		is not needed. However, this could be useful in some cases; for an example, Mylead agent can use this to find the message broker 
		or portal can use this to find all services. Following code shows how to do this with Hasthi Client.</p>
<pre>		
HasthiClient client = new HasthiClient("http://tyr12.cs.indiana.edu:9002");
String[] concreateServiceInstances  = client.lookupAServiceInstances(new QName("Version"));
System.out.println(Arrays.toString(concreateServiceInstances));
</pre>

<p>Also following code can be used to notify Hasthi about any failures</p>
<pre>        
HasthiClient client = new HasthiClient("http://tyr12.cs.indiana.edu:9002");        
client.notifyError("InternarlServerError");
</pre>
<p>I can write REST API to do both actions, if someone needs that please talk to me.</p>
	</body>
</html>